var express = require('express');
var router = express.Router();
var {shopModel,pinglunModel,shoptypeModel,pingModel}=require('../model/model')
router.post('/shopAdd',(req,res)=>{
  shopModel.create(req.body)
  res.send({
    code:200,
    msg:'添加商品成功'
  })
})

router.post('/pinglunAdd',(req,res)=>{
  pinglunModel.create(req.body)
  res.send({
    code:200,
    msg:'添加评论成功'
  })
})
router.post('/pingAdd',(req,res)=>{
  pingModel.create(req.body)
  res.send({
    code:200,
    msg:'添加是否满意成功'
  })
})


router.get('/pinglunlist',async(req,res)=>{
  let data =await pinglunModel.find()
  res.send({
   code:200,
   msg:'展示评论成功',
   data:data
  }) 
 })



router.get('/shoplist',async(req,res)=>{
 let data =await shopModel.find()
 res.send({
  code:200,
  msg:'展示商品成功',
  data:data
 }) 
})
router.post('/shopTypeAdd',(req,res)=>{
  shoptypeModel.create(req.body)
  res.send({
    code:200,
    msg:'添加商品类型成功'
  })
})

router.get('/shopTypelist',async(req,res)=>{
  let data =await shoptypeModel.find()
  res.send({
   code:200,
   msg:'展示商品类型成功',
   data:data
  }) 
 })
router.post('/pinglunAdd',(req,res)=>{
  pinglunModel.create(req.body)
  res.send({
    code:200,
    msg:'添加评论成功'
  })
})
router.post('/pinglunlist',async(req,res)=>{
  let data=await pinglunModel.find()
  res.send({
    code:200,
    msg:'展示评论成功',
    data:data
  })
})


router.put('/shopEdit',async(req,res)=>{
  let body=req.body
  console.log(body);
 let data=await shopModel.updateOne({_id:req.body._id},body)
  res.send({
  code:200,
  msg:'修改成功'
  })
})

router.get('/getshoplist/:id',async(req,res)=>{
  let  id  = req.params.id
  let data=await shopModel.find({_id:id}) 
  res.send({
    code:200,
    msg:'展示成功',
    data:data
  })

})

module.exports = router;
